home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / mfbpntwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  6.4 KB  |  244 lines

  1. /* $XConsortium: mfbpntwin.c,v 5.6 89/11/24 18:03:47 rws Exp $ */
  2. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  3. /***********************************************************
  4. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #include "X.h"
  28.  
  29. #include "windowstr.h"
  30. #include "regionstr.h"
  31. #include "pixmapstr.h"
  32. #include "scrnintstr.h"
  33.  
  34. #include "mfb.h"
  35. #include "maskbits.h"
  36.  
  37. extern void miPaintWindow();
  38.  
  39. /*
  40. NOTE
  41.    PaintArea32() doesn't need to rotate the tile, since
  42. mfbPositionWIndow() and mfbChangeWindowAttributes() do it.
  43. */
  44.  
  45. static void mfbPaintWindow32();
  46.  
  47. void
  48. mfbPaintWindow(pWin, pRegion, what)
  49.     WindowPtr    pWin;
  50.     RegionPtr    pRegion;
  51.     int        what;
  52. {
  53.     register mfbPrivWin    *pPrivWin;
  54.  
  55.     pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
  56.     
  57.     switch (what) {
  58.     case PW_BACKGROUND:
  59.     switch (pWin->backgroundState) {
  60.     case None:
  61.         return;
  62.     case ParentRelative:
  63.         do {
  64.         pWin = pWin->parent;
  65.         } while (pWin->backgroundState == ParentRelative);
  66.         (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, pRegion,
  67.                                  what);
  68.         return;
  69.     case BackgroundPixmap:
  70.         if (pPrivWin->fastBackground)
  71.         {
  72.         mfbPaintWindow32(pWin, pRegion, what);
  73.         return;
  74.         }
  75.         break;
  76.     case BackgroundPixel:
  77.         if (pWin->background.pixel)
  78.         mfbSolidWhiteArea(pWin, REGION_NUM_RECTS(pRegion),
  79.                   REGION_RECTS(pRegion), GXset, NullPixmap);
  80.         else
  81.         mfbSolidBlackArea(pWin, REGION_NUM_RECTS(pRegion),
  82.                   REGION_RECTS(pRegion), GXclear, NullPixmap);
  83.         return;
  84.         }
  85.         break;
  86.     case PW_BORDER:
  87.     if (pWin->borderIsPixel)
  88.     {
  89.         if (pWin->border.pixel)
  90.         mfbSolidWhiteArea(pWin, REGION_NUM_RECTS(pRegion),
  91.                   REGION_RECTS(pRegion), GXset, NullPixmap);
  92.         else
  93.         mfbSolidBlackArea(pWin, REGION_NUM_RECTS(pRegion),
  94.                   REGION_RECTS(pRegion), GXclear, NullPixmap);
  95.         return;
  96.     }
  97.     else if (pPrivWin->fastBorder)
  98.     {
  99.         mfbPaintWindow32(pWin, pRegion, what);
  100.         return;
  101.     }
  102.     break;
  103.     }
  104.     miPaintWindow(pWin, pRegion, what);
  105. }
  106.  
  107. /* Tile Window with a 32 bit wide tile 
  108.    this could call mfbTileArea32, but that has to do a switch on the
  109. rasterop, which seems expensive.
  110. */
  111. static void
  112. mfbPaintWindow32(pWin, pRegion, what)
  113.     WindowPtr pWin;
  114.     RegionPtr pRegion;
  115.     int what;        
  116. {
  117.     int nbox;        /* number of boxes to fill */
  118.     register BoxPtr pbox;    /* pointer to list of boxes to fill */
  119.     int tileHeight;    /* height of the tile */
  120.     register int srcpix;    /* current row from tile */
  121.  
  122.     PixmapPtr pPixmap;
  123.     int nlwScreen;    /* width in longwords of the screen's pixmap */
  124.     int w;        /* width of current box */
  125.     register int nlw;    /* loop version of nlwMiddle */
  126.     register unsigned int *p;    /* pointer to bits we're writing */
  127.     register int h;    /* height of current box */
  128.     register int *psrc;    /* pointer to bits in tile */
  129.     int startmask;
  130.     int endmask;    /* masks for reggedy bits at either end of line */
  131.     int nlwMiddle;    /* number of longwords between sides of boxes */
  132.     int nlwExtra;    /* to get from right of box to left of next span */
  133.     
  134.     int y;        /* current scan line */
  135.  
  136.     unsigned int *pbits;    /* pointer to start of screen */
  137.     mfbPrivWin *pPrivWin;
  138.  
  139.     pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
  140.  
  141.     if (what == PW_BACKGROUND)
  142.     {
  143.     tileHeight = pWin->background.pixmap->drawable.height;
  144.     pPixmap = pPrivWin->pRotatedBackground;
  145.     } 
  146.     else
  147.     {
  148.         tileHeight = pWin->border.pixmap->drawable.height;
  149.     pPixmap = pPrivWin->pRotatedBorder;
  150.     } 
  151.     if (!pPixmap)
  152.     {
  153.     miPaintWindow(pWin, pRegion, what);
  154.     return;
  155.     }
  156.     psrc = (int *)(pPixmap->devPrivate.ptr);
  157.  
  158.     pPixmap = (PixmapPtr)(pWin->drawable.pScreen->devPrivate);
  159.     pbits = (unsigned int *)pPixmap->devPrivate.ptr;
  160.     nlwScreen = (pPixmap->devKind) >> 2;
  161.     nbox = REGION_NUM_RECTS(pRegion);
  162.     pbox = REGION_RECTS(pRegion);
  163.  
  164.     while (nbox--)
  165.     {
  166.     w = pbox->x2 - pbox->x1;
  167.     h = pbox->y2 - pbox->y1;
  168.     y = pbox->y1;
  169.     p = pbits + (pbox->y1 * nlwScreen) + (pbox->x1 >> 5);
  170.  
  171.     if ( ((pbox->x1 & 0x1f) + w) < 32)
  172.     {
  173.         maskpartialbits(pbox->x1, w, startmask);
  174.         nlwExtra = nlwScreen;
  175.         while (h--)
  176.         {
  177.         srcpix = psrc[y%tileHeight];
  178.         y++;
  179.         *p = (*p & ~startmask) | (srcpix & startmask);
  180.         p += nlwExtra;
  181.         }
  182.     }
  183.     else
  184.     {
  185.         maskbits(pbox->x1, w, startmask, endmask, nlwMiddle);
  186.         nlwExtra = nlwScreen - nlwMiddle;
  187.  
  188.         if (startmask && endmask)
  189.         {
  190.         nlwExtra -= 1;
  191.         while (h--)
  192.         {
  193.             srcpix = psrc[y%tileHeight];
  194.             y++;
  195.             nlw = nlwMiddle;
  196.             *p = (*p & ~startmask) | (srcpix & startmask);
  197.             p++;
  198.             Duff (nlw, *p++ = srcpix );
  199.             *p = (*p & ~endmask) | (srcpix & endmask);
  200.             p += nlwExtra;
  201.         }
  202.         }
  203.         else if (startmask && !endmask)
  204.         {
  205.         nlwExtra -= 1;
  206.         while (h--)
  207.         {
  208.             srcpix = psrc[y%tileHeight];
  209.             y++;
  210.             nlw = nlwMiddle;
  211.             *p = (*p & ~startmask) | (srcpix & startmask);
  212.             p++;
  213.             Duff (nlw, *p++ = srcpix );
  214.             p += nlwExtra;
  215.         }
  216.         }
  217.         else if (!startmask && endmask)
  218.         {
  219.         while (h--)
  220.         {
  221.             srcpix = psrc[y%tileHeight];
  222.             y++;
  223.             nlw = nlwMiddle;
  224.             Duff (nlw, *p++ = srcpix);
  225.             *p = (*p & ~endmask) | (srcpix & endmask);
  226.             p += nlwExtra;
  227.         }
  228.         }
  229.         else /* no ragged bits at either end */
  230.         {
  231.         while (h--)
  232.         {
  233.             srcpix = psrc[y%tileHeight];
  234.             y++;
  235.             nlw = nlwMiddle;
  236.             Duff (nlw, *p++ = srcpix);
  237.             p += nlwExtra;
  238.         }
  239.         }
  240.     }
  241.         pbox++;
  242.     }
  243. }
  244.